package item;

import board.BoardUtil;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import game.DataStore;
import board.Tile;
import character.MyCharacter;
import com.jme3.math.Vector3f;
import misc.Vector3i;

public abstract class Item extends Geometry implements Cloneable {
    public static final int DEFAULT_QUANTITY = 1;
    protected int quantity = 1;
    protected MyCharacter owner;
    protected Vector3i boardLocation;

    public Item() {
        this(DEFAULT_QUANTITY);
    }

    public Item(int quantity) {
        super("item", new Box(Tile.SIZE/4, Tile.SIZE/2, Tile.SIZE/4));
	this.quantity = quantity;
        init();
    }
    
    public Item(MyCharacter owner) {
        this(DEFAULT_QUANTITY);
        this.owner = owner;
    }
    
    private void init() {
        Material mat = new Material(DataStore.assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.randomColor());
        setMaterial(mat);
    }

    public int getQuantity() {
	return quantity;
    }

    public void setQuantity(int quantity) {
	this.quantity = quantity;
    }

    public void removeOne() {
	quantity--;
    }

    public void changeQuantity(int amount) {
	quantity += amount;
    }
    
    public MyCharacter getOwner() {
        return owner;
    }
    public void setOwner(MyCharacter owner) {
        this.owner = owner;
    }
    
    public Vector3i getBoardLocation() {
        return boardLocation;
    }

    public void setBoardLocation(Vector3i boardLocation) {
        this.boardLocation = boardLocation;
        setLocalTranslation(BoardUtil.boardToWorld(boardLocation));
    }

    @Override
    public String toString() {
	return this.getClass().getSimpleName()+"("+quantity+")";
    }
    
    @Override
    public Item clone() {
        Item clone = getClass().cast(super.clone());
        clone.setQuantity(quantity);
	clone.setOwner(owner);
	clone.setBoardLocation(boardLocation);
        return clone;
    }
}
